package com.wf.smartcomm.server.client.action;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ModelDriven;
import com.wf.smartcomm.server.bean.Advertisement;
import com.wf.smartcomm.server.bean.House;
import com.wf.smartcomm.server.bean.Village;
import com.wf.smartcomm.server.response.ResponseCode;
import com.wf.smartcomm.server.service.AdService;
import com.wf.smartcomm.server.service.HouseService;
import com.wf.smartcomm.server.service.VillageService;

/** 
 * @author 38884306@qq.com  
 * @version 创建时间：2015-5-26 上午11:56:59 
 * 
 */
@Controller
@Scope("prototype")
public class VillageAction extends BaseAction implements ModelDriven<Village>{

	private Village village = new Village();
	
	@Resource
	private VillageService villageServiceImpl;
	
	@Resource
	private HouseService houseServiceImpl;
	
	@Resource
	private AdService adServiceImpl;
	
	public void list() throws IOException {
		villageServiceImpl.list(page);
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("code", ResponseCode.OK);
		map.put("data", page.getDataList());
		printJsonData(gson.toJson(map));
	}
	
	public void getHouses() throws IOException {
		houseServiceImpl.listByVillage(village, page);
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("code", ResponseCode.OK);
		map.put("data", page.getDataList());
		printJsonData(gson.toJson(map));
	}
	
	public void getAdvertisements() throws IOException{
		adServiceImpl.listByVillage(village, page);
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("code", ResponseCode.OK);
		map.put("data", page.getDataList());
		printJsonData(gson.toJson(map));
	}
	
	@Override
	public Village getModel() {
		// TODO Auto-generated method stub
		return village;
	}

}
